-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Data Views] Remove remaining "any" usage #136343
[Data Views] Remove remaining "any" usage #136343
Conversation
4acfa7d
to
bf3d887
Compare
Pinging @elastic/kibana-app-services (Team:AppServicesUx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kibana-gis changes LGTM
code review
waitInMs: number | ||
): ((key: string) => F) => { | ||
const debouncerCollector: Record<string, F> = {}; | ||
export const debounceByKey = <F extends (...args: any) => unknown>(fn: F, waitInMs: number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a way to get rid of this any
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to leave a code comment
} from './lib'; | ||
export type { RollupIndexCapability } from './lib'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be exported since its part of a public API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you document it? Trying to prevent Public APIs missing comments
from increasing
const isMultiple = intervals[1] % intervals[0] === 0; | ||
fieldAgg.interval = isMultiple ? intervals[1] : intervals[0] * intervals[1]; | ||
if (fieldAgg) { | ||
const aggInterval = (agg as any).interval ?? agg.calendar_interval; // FIXME the interface infers only that calendar_interval property is valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find an interval
field on the interface that is expected here, I thought maybe it should be calendar_interval
-- or maybe the typings are not complete for the histogram agg
@@ -7,7 +7,7 @@ | |||
|
|||
import type { IndexPatternAggRestrictions } from '@kbn/data-plugin/public'; | |||
import type { FieldSpec } from '@kbn/data-plugin/common'; | |||
import type { FieldFormatParams } from '@kbn/field-formats-plugin/common'; | |||
import type { FieldFormatMap } from '@kbn/data-views-plugin/common'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why FieldFormat
and FieldFormatParams
are exported from the field-formats
plugin,
but FieldFormatMap
is exported from the data-views
plugin. 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FieldFormatMap is how data views saves field formatters
@@ -92,7 +93,7 @@ export function convertDataViewIntoLensIndexPattern(dataView: DataView): IndexPa | |||
Object.fromEntries( | |||
Object.entries(fieldFormatMap).map(([id, format]) => [ | |||
id, | |||
'toJSON' in format ? format.toJSON() : format, | |||
'toJSON' in format ? (format as unknown as FieldFormat).toJSON() : format, // FIXME SerializedFieldFormat was inferred... was this intended to work with FieldFormat instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need reviewers to look closely at this: I could not see how there would be a .toJSON
property on this object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of notes otherwise great work!
*/ | ||
export function shortenDottedString(input: any) { | ||
return typeof input !== 'string' ? input : input.replace(DOT_PREFIX_RE, '$1.'); | ||
export function shortenDottedString(input: unknown): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this called on something aside from a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was only in unit tests
@@ -432,7 +432,7 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { | |||
|
|||
let formatter: { convert: (data: unknown) => string }; | |||
if (indexPattern.fieldFormatMap && indexPattern.fieldFormatMap[field.name]) { | |||
const FormatType = fieldFormats.getType(indexPattern.fieldFormatMap[field.name].id); | |||
const FormatType = fieldFormats.getType(indexPattern.fieldFormatMap[field.name].id as string); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps fieldFormats.getType
needs better type info instead of using as string
on the id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change in this PR is to type-guard that indexPattern.fieldFormatMap[field.name].id
is a string, because an argument to FieldFormatsRegistry.getType
is required: https://github.com/elastic/kibana/blob/8.3/src/plugins/field_formats/common/field_formats_registry.ts#L92
Hm, checking against main, the "fieldFormats" object was typed as FieldFormatsStart
not FieldFormatsRegistry
. Need to look into this.
Edit: this change came from the type refinement where indexPattern.fieldFormatMap
was typed as:
(property) IndexPattern.fieldFormatMap?: Record<string, {
id: string;
params: SerializableRecord;
}>
But is now: IndexPattern.fieldFormatMap?: FieldFormatMap
, which types to Record<string, SerializedFieldFormat>
, and types to this:
export type SerializedFieldFormat<
P = {},
TParams extends FieldFormatParams<P> = FieldFormatParams<P>
> = {
id?: string;
params?: TParams;
};
With the refined types, id
is now inferred to be optional. The previous typing from this code assumed id
and params
is not optional: https://github.com/elastic/kibana/blob/8.3/x-pack/plugins/lens/public/indexpattern_datasource/types.ts#L59-L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have zero understanding what consequences this might bring but it would be nice if id
could be required. I guess params too if that works with existing code. Perhaps an empty object is always provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the object could come from user input, and the ID is not validated to be present: https://github.com/elastic/kibana/blob/8.3/src/plugins/data_views/server/rest_api_routes/util/schemas.ts#L13.
There is quite a lot of test code that relies on these fields being optional as well.
It looks like the code metric script finds that |
💚 CLA has been signed |
3cca8c7
to
250d034
Compare
c9de913
to
2a2d14a
Compare
@@ -100,6 +100,7 @@ export function convertDataViewIntoLensIndexPattern(dataView: DataView): IndexPa | |||
Object.fromEntries( | |||
Object.entries(fieldFormatMap).map(([id, format]) => [ | |||
id, | |||
// @ts-expect-error FIXME Property 'toJSON' does not exist on type 'SerializedFieldFormat' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dej611 I remember we were struggling a bit with this - do you know where this is coming from? How can there be a toJSON
on the format that should be serialized? Was this done to work around some bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VisEditors changes LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes lgtm - nice type improvements!
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Any counts in public APIs
Async chunks
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
Follows #135767
This removes the remaining
any
from production code and code comments insrc/plugins/data_v*
Note: some instances have remained due to ambiguity in the code, but these have had added FIXME comments:
After this PR, the remaining matches of the term
any
exist in the following:any
Remaining
any
matches: